package cn.edu.cqvie.ssm.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cqvie.ssm.model.UserModel;
import cn.edu.cqvie.ssm.model.impl.UserModelImpl;
import lombok.extern.log4j.Log4j2;

/**
 * Servlet implementation class CheckLogin
 */
@WebServlet("/CheckLogin")
//@Log4j2
public class CheckLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckLogin() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request , response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
		request.setCharacterEncoding("UTF-8");
		String user = (String)request.getParameter("user");
		String password = (String)request.getParameter("password");
//		log.info(user+";"+password);
		System.out.println(user+";"+password);
		UserModel um = new UserModelImpl();
		
		PrintWriter out = response.getWriter();
		if(um.find(user,password) ) {
			out.println(true);
			System.out.println(true);
//			log.info("true");
		}else {
			out.println(false);
//			log.info("false");
			System.out.println(false);
		}
		out.flush();
		out.close();
	}

}
